package com.goktech.olala.client.controller.index;

import com.goktech.olala.core.service.IIndexService;
import com.goktech.olala.server.pojo.goods.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @Classname IndexController
 * @Description TODO
 * @Date 2020/12/26 20:10
 * @Created by wjs
 */
@Controller
public class IndexController {
    @Autowired
    IIndexService indexService;

    @RequestMapping("/index/init.do")
    public ModelAndView init() {
        //创建一个modelAndView
        ModelAndView modelAndView = new ModelAndView();

        //查询新闻头条列表
        List<Article> articles = indexService.selectAllArticle();
        modelAndView.addObject("articleVoList", articles);
        //查询热门活动列表
        List<Activit> activits = indexService.selectAllActivit();
        modelAndView.addObject("indexActivities", activits);
        //查询首站轮播图
        List<Advers> advers = indexService.selectAllAdvers();
        modelAndView.addObject("ctmAdvers", advers);
        //查询品牌分类列表
        List<ParentCategory> parentCategories = indexService.selectAllCategory();
        modelAndView.addObject("categoryList", parentCategories);

        modelAndView.setViewName("home/index");
        return modelAndView;
    }


    @RequestMapping("/goodsIndexApi/queryGoodsByParam.do")
    public ModelAndView queryGoodsByParam(String keywords,Integer page) throws Exception {
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("keywords", keywords);
        //查询商品
        List<GoodsVO> goods = indexService.searchGoods(keywords,page);
        modelAndView.addObject("goodsList", goods);
        //品牌
        List<GoodsBrand> goodsBrands = indexService.searchBrand(keywords);
        modelAndView.addObject("brandList", goodsBrands);
        //种类
        List<Category> categoryList = indexService.searchCategory(keywords);
        modelAndView.addObject("categoryList", categoryList);
        //选购热点
        List<GoodsReport> goodsReports = indexService.searchHotSale(keywords);
        modelAndView.addObject("hotSaleList", goodsReports);

        modelAndView.setViewName("home/search");
        return modelAndView;
    }

    @RequestMapping("/goodsIndexApi/queryGoodsDetail.do")
    public ModelAndView queryGoodsDetail(String goodsId){
        ModelAndView modelAndView = new ModelAndView();

        GoodsVO2 goodsVO2 = indexService.queryGoodsDetail(goodsId);
        modelAndView.addObject("goodsInfo",goodsVO2);

        modelAndView.setViewName("home/introduction");
        return modelAndView;
    }
}
